<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Get</title>
    <style>
        #result{
            widows: 200px;
            height: 100px;
            border: 1px solid #909090;
        }
    </style>
</head>
<body>
    <button>Click send request</button>
    <div id="result"></div>
</body>
<script>
    // 获取button
    const btn = document.getElementsByTagName("button")[0];
    const result = document.getElementById("result");
    btn.onclick = function(){
        // 创建对象
        const xhr = new XMLHttpRequest();
        xhr.responseType = "json";
        // 初始化
        xhr.open("GET", "http://127.0.0.1:8888/json-server");
        // 发送
        xhr.send();
        // 事件绑定 处LO理返回结果
        xhr.onreadystatechange = function (){
            if(xhr.readyState == 4) {
                if(xhr.status == 200){
                    result.innerHTML = xhr.response.number;
                }
            }
        }
    };
</script>
</html>